package ch.fusun.baron.basic.command;

import ch.fusun.baron.core.injection.Configure;
import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.farm.FarmService;
import ch.fusun.baron.map.Tile;
import ch.fusun.baron.player.Dynasty;
import ch.fusun.baron.player.Player;
import ch.fusun.baron.player.api.PlayerService;
import ch.fusun.baron.property.api.PropertyService;

/**
 * Command to create a farm
 */
public class CreateFarmCommand extends MoneyTurnCommand {

	@Configure(value = "10")
	private int MONEY;

	@Configure(value = "10")
	private int TURN_COST;

	private Dynasty dynasty;
	private Tile tile;

	@Inject
	private transient FarmService farmService;
	@Inject
	private transient PropertyService propertyService;
	@Inject
	private transient PlayerService playerService;

	/**
	 * Injection constructor
	 */
	public CreateFarmCommand() {
	}

	/**
	 * @param dynasty
	 *            The player
	 * @param tile
	 *            The tile
	 */
	public CreateFarmCommand(Dynasty dynasty, Tile tile) {
		this.dynasty = dynasty;
		this.tile = tile;
	}

	@Override
	public boolean isAllowedImpl() {
		return dynasty.equals(playerService.getDynasty((Player) propertyService
				.getOwnership(propertyService.getOwnership(tile))));
	}

	@Override
	public void executeImpl() {
		farmService.createFarm(tile);
	}

	@Override
	protected int getTurnCost() {
		return TURN_COST;
	}

	@Override
	protected Dynasty getDynasty() {
		return dynasty;
	}

	@Override
	protected int getMoneyCost() {
		return MONEY;
	}

}
